#include <iostream>
#include <string>
#include <cstring>
using namespace std;
bool isScramble(string s1,string s2){
    if(s1 == s2)return true;
    int l = s1.size();
    if(l!=s2.size())return false;
    int t[26]={0};
    for (int j = 0; j < l; ++j) {
        t[s1[j]-'a']++;
        t[s2[j]-'a']--;
    }
    for (int k = 0; k < 26; ++k) {
        if(t[k]!=0){
            cout<<"here"<<endl;

            return false;
        }
    }

    cout<<"here"<<endl;
    for(int i=1;i<l;i++){
        cout<<"here1:"<<s1.substr(0,i)<<","<<s2.substr(0,i)<<","<<s1.substr(i)<<","<<s2.substr(i)<<endl;
        if(isScramble(s1.substr(0,i),s2.substr(0,i))&&isScramble(s1.substr(i),s2.substr(i))){
            return true;
        }
        cout<<"here2:"<<s1.substr(0,i)<<","<<s2.substr(l-i)<<","<<s1.substr(i)<<","<<s2.substr(0,l-i)<<endl;
        if(isScramble(s1.substr(0,i),s2.substr(l-i))&&isScramble(s1.substr(i),s2.substr(0,l-i))){
            cout<<"return true;"<<endl;
            return true;
        }
    }
    return false;
}

int main() {
    std::cout << isScramble("adbc","dbca") << std::endl;

    return 0;
}